<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Default functionality</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/dropdown.css">
<link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Slab:400,700' rel='stylesheet' type='text/css'> 
<script>
$(function() {
	var dpFrom = $( "#datepicker-from" ).datepicker({
		onSelect : function(e,f){
			console.log({e:e,f:f,date: new Date()});
			var dateObj = new Date(f.selectedYear,f.selectedMonth,f.selectedDay);
			
			var dateFromString = [dateObj.getFullYear(),
			["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"][dateObj.getMonth()],
			(f.selectedDay.length < 2) ? "0" +dateObj.getDate() : dateObj.getDate()].join('')
			console.log(dateFromString);
		}
	});
	var dpTo = $( "#datepicker-to" ).datepicker({
		onSelect : function(e,f){
			console.log({e:e,f:f,date: new Date()});
			var dateObj = new Date(f.selectedYear,f.selectedMonth,f.selectedDay);
			
			var dateToString = [dateObj.getFullYear(),
			["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"][dateObj.getMonth()],
			(f.selectedDay.length < 2) ? "0" +dateObj.getDate() : dateObj.getDate()].join('')
			console.log(dateToString);
		}
	});
	dpFrom.datepicker({ dateFormat: 'yy-mm-dd' });
	dpTo.datepicker({ dateFormat: 'yy-mm-dd' });
	
	dpTo.datepicker("setDate", new Date());
	
	var myD = '20130101'.match(/.{1,2}/g);
	console.log(myD[0]+myD[1]);
	
	dpFrom.datepicker("setDate", new Date(myD[0]+myD[1], myD[2]-1, myD[3]));
	
	
	/*var queryDate = '2009-11-01',
    dateParts = queryDate.match(/(\d+)/g)
    realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]); 
	dpFrom.datepicker("setDate", realDate);
	console.log('realDate ' + realDate);*/
	
	
	$('#open-dialog').click(function(){
		$('#modal').dialog({
			height:140,
			modal:true
		})
	});
});

</script>
</head>
<body>
<p>From: <input type="text" id="datepicker-from" /></p>
<p>To: <input type="text" id="datepicker-to" /></p>

<a id="open-dialog">Open</a>

<div id="modal">sdfsdfsf</div>
</body>
</html>